package logic

import (
	"context"
	"user-goods/models/mysql"

	"user-goods/userrpc/internal/svc"
	"user-goods/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodAddLogic {
	return &GoodAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodAddLogic) GoodAdd(in *userrpc.GoodAddRequest) (*userrpc.GoodAddResponse, error) {
	// todo: add your logic here and delete this line

	good := mysql.Goods{
		GoodName: in.GoodName,
		Price:    float64(in.Price),
		Num:      in.Num,
		UserId:   in.UserId,
	}
	mysql.DB.Debug().Create(&good)

	return &userrpc.GoodAddResponse{
		GoodId: int64(good.ID),
	}, nil
}
